<?php
class DataUtil{

	const VALUE_YES='1';
	const VALUE_NO='0';
	
	private static $_timeCache=array();

	public static function option_yes_no(){
		return array(self::VALUE_YES=>'Yes',self::VALUE_NO=>'No');
	}

	public static function option_yes_no_empty(){
		return array(''=>'',self::VALUE_YES=>'Yes',self::VALUE_NO=>'No');
	}

	public static function getStartOfDay($time){
		$dateTime=getdate($time);
		return mktime (0,0,0, $dateTime['mon'], $dateTime['mday'], $dateTime['year']);
	}
	
	public static function getStartOfToday(){
		if(!isset(self::$_timeCache['today'])){
			self::$_timeCache['today']=self::getStartOfDay(time());
		}
		return self::$_timeCache['today'];
	}

	public static function getStartOfWeek($time){
		$dateTime=getdate($time);
		$time=mktime (0,0,0, $dateTime['mon'], $dateTime['mday'], $dateTime['year']);
		return $time-86400*(($dateTime['wday']+6)%7);
	}

	public static function getStartOfThisWeek(){
		if(!isset(self::$_timeCache['thisWeek'])){
			self::$_timeCache['thisWeek']=self::getStartOfWeek(time());
		}
		return self::$_timeCache['thisWeek'];
	}
	
	const STATUS_PENDING='0';
	const STATUS_REJECTED='1';
	const STATUS_APPROVED='2';

	public static function status_options($status=null){
		$status_options= array(
		self::STATUS_PENDING=>'Pending',
		self::STATUS_REJECTED=>'Rejected',
		self::STATUS_APPROVED=>'Approved',
		);
		$status=strval($status);
		if($status!==null&&isset($status_options[$status])){
			return $status_options[$status];
		}
		return $status_options;
	}

	public static function getOpeningHoursOptions() {
		$result=array();
		for($h=0;$h<=24;$h++){
			for($m=0;$m<=4;$m++){
				$hour=sprintf('%02d:%02d',$h,$m*15);
				$result[$hour]=$hour;
			}
		}
		return $result;
	}
}